from django.core.management.base import BaseCommand
from myUser.models import video
from myUser.models import VideoTags
import random
from dateutil.relativedelta import relativedelta
from datetime import datetime, timedelta


# python manage.py create_data
# delete from myUser_video;

class Command(BaseCommand):
    help = '创建测试视频数据'

    def handle(self, *args, **options):
        self.create_video_data()

    def create_video_data(self):
        # 获取所有标签
        time_tags = VideoTags.TIME_CHOICES
        type_tags = VideoTags.TYPE_CHOICES
        length_tags = VideoTags.LENGTH_CHOICES
        hot_tags = VideoTags.HOT_CHOICES
        class_tags = VideoTags.CLASS_CHOICES
        # 定义演员和导演数据池
        actors = ["张国荣,梁朝伟", "周星驰,朱茵", "周润发,张曼玉", "刘德华,张学友", "成龙,李连杰"]
        directors = ["王家卫", "张艺谋", "李安", "吴宇森", "陈凯歌"]

        base_date = datetime(2020, 1, 1)
        start_date = base_date + relativedelta(years=-10)
        end_date = base_date + relativedelta(years=10)

        videos_data = []
        for i in range(1, 100):
            random_date = (start_date + timedelta(days=random.randint(0, (end_date - start_date).days))).date()
            videos_data.append({
                "title": f"测试视频{i}",
                "info": f"这是测试视频{i}的简介",
                "time": random_date,
                "actor": random.choice(actors),
                "director": random.choice(directors),
                "time_tag": random.choice(time_tags[1:])[0],
                "type_tag": random.choice(type_tags[1:])[0],
                "length_tag": random.choice(length_tags[1:])[0],
                "hot_tag": random.choice(hot_tags[1:])[0],
                # "hot_tag": "HOT",
                "class_tag": random.choice(class_tags[1:])[0],
                # "class_tag": "VIP",
            })
        for data in videos_data:
            video.objects.create(**data)

        self.stdout.write(self.style.SUCCESS('成功创建测试视频数据'))
